<?php $this->_extends('_layouts/basic_layout'); ?>

<?php $this->_block('resource'); ?>

<?php $this->_endblock(); ?>

<?php $this->_block('title'); ?>
	Jquery Plugins
<?php $this->_endblock(); ?>

<?php $this->_block('admin_contents'); ?>
<div class="row-fluid">	
	<a class="btn btn-info" href="<?php echo url('jqueryplugins/index');?>">返回列表</a>
</div>
<div class="row-fluid">	<!--  sortable ui-sortable -->
	<div class="box span12">
		<div class="box-header well">
			<h2>
				<i class="icon-edit"></i>
				编辑Jquery插件
			</h2>
		</div>
		
		<div class="box-content">
			<form class="form-horizontal" id="jqplugin-editForm" enctype="multipart/form-data" method="post" action="<?php echo url('jqueryplugins/edit', array('id' => $jqPlugins->attributes['id'])); ?>">
				<fieldset>
					<legend><?php echo isset($jqPlugins->attributes['name']) ? $jqPlugins->attributes['name'] : '编写';?></legend>
				</fieldset>
				<div class="control-group">
					<label class="control-label" for="form[name]">插件名称: </label>
					<div class="controls">
						<input type="text" class="input-text" name="form[name]" value="<?php echo isset($jqPlugins->attributes['name']) ? $jqPlugins->attributes['name'] : '';?>" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="form[type_id]">插件类别: </label>
					<div class="controls">
						<select id="type" name="form[type_id]">
							<?php if(!empty($jqueryplugins_type)): foreach($jqueryplugins_type as $k => $t): ?>
								<option value="<?php echo $t['id'] ?>"><?php echo $t['name'] . '(' . $t['name_en'] . ')'; ?></option>
							<?php endforeach; endif; ?>
						</select>
						<script type="text/javascript">
							$('#type').val('<?php echo isset($jqPlugins->attributes['type_id']) ? $jqPlugins->attributes['type_id'] : '';?>');
						</script>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="form[root_foldername]">文件存放根目录名称: </label>
					<div class="controls">
						<input type="text" class="input-text" name="form[root_foldername]" value="<?php echo isset($jqPlugins->attributes['root_foldername']) ? $jqPlugins->attributes['root_foldername'] : '';?>" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="form[sketch]">概述: </label>
					<div class="controls">
						<input type="text" class="input-text" name="form[sketch]" value="<?php echo isset($jqPlugins->attributes['sketch']) ? $jqPlugins->attributes['sketch'] : '';?>" />
					</div>
				</div>
				<div class="control-group attach-line">
					<label class="control-label">附件: </label>
					<div class="controls">
						<input type="file" class="input-text" name="form[attachment][]" data-no-uniform="true" />
						<a href="javascript: void(0);" class="cancel-attach">取消附件</a>
					</div>
				</div>
				<div class="control-group">
					<div class="controls">
						<a class="btn btn-info" id="add-attach-btn" href="javascript:void(0);">添加附件</a>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="form[thumbnail]">缩略图: </label>
					<div class="controls">
						<input type="file" class="input-text" name="form[thumbnail]" value="" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="form[download_pack]">下载包: </label>
					<div class="controls">
						<input type="file" class="input-text" name="form[download_pack]" />
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">详细内容</label>
				</div>
				<div class="control-group">
					<textarea name="form[description]" id="jq-plugin-desc"></textarea>
				</div>
				<div class="control-group">
					<div class="controls">
						<p class="help-block">
							可用变量:<br />
								<?php 
									foreach($jqPlugins->descriptionVars as $name => $desc){
										echo '&nbsp;&nbsp;&nbsp;&nbsp;' . $name . ': ' . $desc . '<br />';
									}
								?>
						</p>
					</div>
				</div>
				<div class="form-actions">
					<button class="btn btn-primary" type="submit" value="编辑">编辑</button>
					<button class="btn" type="reset">Cancel</button>
				</div>
			</form>
		</div>
	</div>
</div>

<script type="text/javascript" src="/markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="/markitup/sets/default/set.js"></script>
<link rel="stylesheet" type="text/css" href="/markitup/skins/markitup/style.css" />
<link rel="stylesheet" type="text/css" href="/markitup/sets/default/style.css" />
<script type="text/javascript">
	mySettings.replaceMark = <?php echo json_encode($jqPlugins->descriptionVarsTrans()); ?>;
	mySettings.resizeHandle = false;
	mySettings.previewAutoRefresh = true;
	$('#jq-plugin-desc').markItUp(mySettings).val(<?php echo isset($jqPlugins->attributes['description']) ? json_encode($jqPlugins->attributes['description']) : '';?>);
</script>


<?php $formErrors = json_encode($jqPlugins->getValidateError()); ?>
<script>
	$('#add-attach-btn').data('oriLine', $('.attach-line').first().htmlCode());

	$('#add-attach-btn').click(function(){
		var newLine = $(this).data('oriLine');
		$(newLine).find('input').val('');
		$(this).parent().parent().before($(newLine));
	});

	$('.cancel-attach').live('click', function(){
		$(this).parent().parent('.attach-line').remove();
	});

	$.each(<?php echo $formErrors; ?>, function(item, errors){
		$.each(errors, function(k, error){
			noty({
				'text': item + ': ' + error,
				'layout': 'topRight',
				'type': 'error'
			});
		});
	});
</script>
<?php $this->_endblock(); ?>